/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ServiceInterface;
import Utilities.Constants;
import CommonData.CommonDataManager;
import DataModel.*;
import Organization.OrganizationManager;
import Project.*;
import Schedule.ScheduleManager;
import User.UserManager;
import Utilities.DataAccesor;
import java.sql.Connection;
import javax.ejb.Stateless;
import java.util.Date;

/**
 *
 * @author Carlos
 */
@Stateless(mappedName="SAFPFacade")
public class SAFPFacade implements IFacade
{
    // <editor-fold defaultstate="collapsed" desc="Otros">
    @Override
    public Country[] GetCountries()
    {
        return CommonDataManager.GetInstance().GetCountries();
    }

    @Override
    public Connection GetReportConnection()
    {
        try
        {
            return DataAccesor.GetNewConnection();
        }
        catch(Exception ex)
        {
            return null;
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Schedule Methods">
    @Override
    public void RegisterAdvance(int activityId, Date date, double advance, double spentBudget)
    {
        ScheduleManager.GetInstance().RegisterAdvance(activityId, date, advance, spentBudget);
    }

    @Override
    public Advance[] GetAdvances(int activityId)
    {
        return ScheduleManager.GetInstance().GetAdvances(activityId);
    }

    @Override
    public Activity GetActivity(int activityId)
    {
        return ScheduleManager.GetInstance().GetActivity(activityId);
    }

    @Override
    public ActivitySummary[] GetSchedule(int projectId)
    {
        return ScheduleManager.GetInstance().GetCurrentSchedule(projectId);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Payment Methods">
    @Override
    public PaymentBase[] GetProjectPayments(int projectId)
    {
        return PaymentManager.GetInstance().GetProjectPayments(projectId);
    }

    @Override
    public Payment GetPayment(int paymentId)
    {
        return PaymentManager.GetInstance().GetPayment(paymentId);
    }

    @Override
    public void RegisterPayment(int paymentId, Date date, double amount)
    {
        PaymentManager.GetInstance().RegisterPayment(paymentId, date, amount);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Project Methods">
    @Override
    public Project GetProject(int projectId)
    {
        return ProjectManager.GetInstance().GetProject(projectId);
    }

    @Override
    public void AssingProjectOfficer(int projectId, int officerId)
    {
        ProjectManager.GetInstance().AssingProjectOfficer(projectId, officerId);
    }

    // <editor-fold defaultstate="collapsed" desc="Get Projects">
    @Override
    public ProjectSummary[] GetProjects(Enums.ProjectState status, Enums.ProjectType type, int pageNumber)
    {
        return ProjectManager.GetInstance().GetProjects(status, type, pageNumber, Constants.DISPLAY_ITEMS);
    }

    @Override
    public ProjectSummary[] GetProjectsByType(Enums.ProjectType type, int pageNumber)
    {
        return ProjectManager.GetInstance().GetProjectsByType(type, pageNumber, Constants.DISPLAY_ITEMS);
    }

    @Override
    public ProjectSummary[] GetProjectsByCountry(int countryId, Enums.ProjectType type, int pageNumber)
    {
        return ProjectManager.GetInstance().GetProjectsByCountry(countryId, type, pageNumber, Constants.DISPLAY_ITEMS);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Count Projects">
    @Override
    public int GetProjectsCount(Enums.ProjectType type, Enums.ProjectState status)
    {
        return ProjectManager.GetInstance().GetProjectsCount(type, status);
    }

    @Override
    public int GetProjectsCount(Enums.ProjectType type)
    {
        return ProjectManager.GetInstance().GetProjectsCount(type);
    }

    @Override
    public int GetProjectsCount(Enums.ProjectType type, int countryId)
    {
        return ProjectManager.GetInstance().GetProjectsCount(type, countryId);
    }
    // </editor-fold>
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Organization Methods">
    @Override
    public Organization GetOrganization(int organizationId)
    {
        return OrganizationManager.GetInstance().GetOrganization(organizationId);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Request Methods">
    @Override
    public void ApproveRequest(int requestId)
    {
        ProjectManager.GetInstance().ApproveRequest(requestId);
    }

    @Override
    public void RejectRequest(int requestId)
    {
        ProjectManager.GetInstance().RejectRequest(requestId);
    }

    @Override
    public Project[] GetIncompleteRequests(int userId)
    {
        return ProjectManager.GetInstance().GetIncompleteRequests(userId);
    }

    @Override
    public Project GetIncompleteRequest(int userId, int requestId)
    {
        return ProjectManager.GetInstance().GetIncompleteRequest(userId, requestId);
    }

    @Override
    public boolean CreateRequest(String name, Date iniDate, Date endDate, String bankAcc, double iniBudget,
            int countryId, String description, String objectives, int orgId, int userId)
    {
        return ProjectManager.GetInstance().CreateRequest(name, iniDate, endDate, bankAcc, iniBudget, countryId, description, objectives, orgId, userId);
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="User Methods">
    @Override
    public PersonSummary[] GetUsersInRole(Enums.UserRole role)
    {
        return UserManager.GetInstance().GetUsersInRole(role);
    }
    // </editor-fold>

}
